<?php
namespace app\index\controller;
use app\index\logic\IndexLogic;

/**
 * Created by PhpStorm.
 * User: tyll
 * Date: 2019/09/05
 * Time: 16:13
 */
class Index extends Base {

    public function __construct(){
        parent::__construct();
        $this->i_logic = new IndexLogic();
    }

    /**
     * 检查token是否过期
     * @return \think\response\Json
     */
    public function ajax_check_token(){
        $params = input();
        $r = $this->check_user_token($params);
        return json($r);
    }

    /**
     * 检查个人中心是否待办事项、工作圈消息红点
     * @return \think\response\Json
     */
    public function ajax_check_red_point(){
        $params = input();
        $r = $this->check_user_token($params);
        if($r['code'] != 1){
            return json($r);
        }

        //检查用户规则
        $r = $this->i_logic->check_user_rule();
        if($r['code'] != 1){
            return json($r);
        }
        $u_detail = $r['data']['detail'];

        //获取待办事项未读数量
        $maps = [];
        $maps[] = ['deal_openid','=',$u_detail['openid']];
        $maps[] = ['status','=',2];
        $wm_no_read_num = model('matter')->get_count($maps,'id');

        //获取工作圈新消息数量
        $maps = [];
        $maps[] = ['c_time','>',$params['start_time']];
        $new_msg_num = model('work_circle_msg')->get_count($maps,'id');

        //获取累计访问数量
        $cvr = new \app\common\controller\CountVisitorRecord();
        $r = $cvr->count_home_vr_num();
        $home_vr_num = $r['num'];

        $data['wm_no_read_num'] = $wm_no_read_num;
        $data['new_msg_num'] = $new_msg_num;
        $data['home_vr_num'] = $home_vr_num;
        return json($this->i_logic->get_response(1,'OK',$data));
    }
}
